package spring.cloud.study.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.study.entity.base.ResponseModel;
import spring.cloud.study.entity.base.ResponseResult;
import spring.cloud.study.entity.user.User;

@RestController
@Slf4j
public class ProviderController {

	@Value("${server.port}")
	private String serverPort;

	@GetMapping(value = "/provider/get/{id}")
	public ResponseModel getPaymentById(@PathVariable("id") Long id) {

		if (id != null) {
			return ResponseModel.successMsg("查询成功,serverPort:  " + serverPort);
		} else {
			return ResponseModel.errorMsg("查询失败，ID不能为空 ");
		}
	}

	@GetMapping(value = "/provider/getSp")
	public ResponseResult<String> getSp() {
		ResponseResult<String> res = new ResponseResult<String>(serverPort);
		return res;
	}
	
	@GetMapping(value = "/provider/addUser")
	public ResponseResult<User> addUser(){
		ResponseResult<User> res = new ResponseResult<User>();
		User user = new User();
		user.setUserId(RandomUtil.randomLong());
		user.setUserName(RandomUtil.randomString(10));
		return res.success(user,"端口：" + serverPort);
	}
}
